Get Your Hands Dirty on Clean Architecture by Tom Hombergs

Get Your Hands Dirty on Clean Architecture by Tom Hombergs

Author:Tom Hombergs
Language: eng
Format: epub
Publisher: Packt Publishing
Published: 2019-09-26T16:00:00+00:00


What about Database Transactions?

We have not touched upon the topic of database transactions yet. Where do we put our transaction boundaries?

A transaction should span all write operations to the database that are performed within a certain use case so that all those operations can be rolled back together if one of them fails.

Since the persistence adapter doesn't know which other database operations are part of the same use case, it cannot decide when to open and close a transaction. We have to delegate this responsibility to the services that orchestrate the calls to the persistence adapter.

The easiest way to do this with Java and Spring is to add the @Transactional annotation to the application service classes so that Spring will wrap all public methods with a transaction:

package buckpal.application.service;

@Transactional

public class SendMoneyService implements SendMoneyUseCase {

...

}

If we want our services to stay pure and not be stained with @Transactional annotations, we can use aspect-oriented programming – for example, with AspectJ – in order to weave transaction boundaries into our codebase.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.